<?php

namespace App\Jobs;
use App\Facades\Site;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mail,Log;

class PersonalRegisterEmail extends Job implements ShouldQueue{
    use InteractsWithQueue, SerializesModels;
    protected $userInfo;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userInfo){
        $this->userInfo = $userInfo;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(){
        $this->config();
        if(!empty(Site::get('MailAddress'))){
            Mail::send('emails.personal_register_email', ['userInfo' => $this->userInfo], function ($m)  {
                $m->from(Site::get('MailAddress'), Site::get('webname'));
                $m->to($this->userInfo->email)->subject(Site::get('webname').'-个人会员账号');
            });
        }else{
            Log::info('发送邮件失败');
        }
    }
}
